//
//  BLRechargeViewController.m
//  blanket
//
//  Created by Mac on 2017/12/4.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "BLRechargeViewController.h"
#import "BLRechageRecordViewController.h"
#import "BLRechargeOffLineViewController.h"
#import "BLRechargeOnlineViewController.h"
#import "BLConsumeViewController.h"
@interface BLRechargeViewController ()
@property(nonatomic, strong) STLabel                     *moneyLable;
@property(nonatomic, strong) STLabel                     *pointLable;
@property(nonatomic, strong) STLabel                     *washLable;
@property(nonatomic, strong) STLabel                     *lastWashLable;
@property(nonatomic, strong) BLUserModel                     *userModel;
@end

@implementation BLRechargeViewController


#pragma mark --vc 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"盖币充值";
    [self configSubView];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self sendMyInfoRequest];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    header.backgroundColor = [UIColor whiteColor];
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 200)];
    // imageView.image = [UIImage imageNamed:@"abnner2"];
    imageView.backgroundColor = BL_BlueBackGroundColor;
    [header addSubview:imageView];
    
    UIImageView * iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 25, 21, 21)];
    iconImageView.image = [UIImage imageNamed:@"盖币"];
    iconImageView.centerX = UIScreenWidth / 2;
    [imageView addSubview:iconImageView];
    
    self.moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(10, iconImageView.bottom + 10, UIScreenWidth - 20, 20)
                                                text:@"盖币:0.00"
                                           textColor:[UIColor whiteColor]
                                                font:14
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentCenter];
    [imageView addSubview:self.moneyLable];
    
    self.pointLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.moneyLable.bottom + 10, UIScreenWidth - 20, 20)
                                                text:@"积分:0.00"
                                           textColor:[UIColor whiteColor]
                                                font:14
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentCenter];
    [imageView addSubview:self.pointLable];
    
    self.washLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.pointLable.bottom + 10, UIScreenWidth - 20, 20)
                                               text:@"本月洗涤:0.00"
                                          textColor:[UIColor whiteColor]
                                               font:14
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentCenter];
    [imageView addSubview:self.washLable];
    
    self.lastWashLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.washLable.bottom + 10, UIScreenWidth - 20, 20)
                                                   text:@"本月洗涤:0.00"
                                              textColor:[UIColor whiteColor]
                                                   font:14
                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentCenter];
    [imageView addSubview:self.lastWashLable];
    
    STLabel * desLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.lastWashLable.bottom + 10, UIScreenWidth - 20, 20)
                                                   text:@"洗涤清单费用请联系客服"
                                              textColor:[UIColor whiteColor]
                                                   font:14
                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentCenter];
    [imageView addSubview:desLable];
    
    
    UIView * line1 = [[UIView alloc] initWithFrame:CGRectMake(0, imageView.bottom, UIScreenWidth, 0.5)];
    line1.backgroundColor = BL_lineColor;
    [header addSubview:line1];
    
    __weak typeof(self) weakSelf =  self;
    STButton * onLineButton = [[STButton alloc] initWithFrame:CGRectMake(0, line1.bottom, UIScreenWidth / 2, 54)
                                                        title:@"线上充值"
                                                   titleColor:KL_secendTextColor
                                                    titleFont:14
                                                 cornerRadius:0
                                              backgroundColor:nil
                                              backgroundImage:nil
                                                        image:nil];
    onLineButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [onLineButton st_showRightLine:20];
    [onLineButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedOnlineButton];
    }];
    [header addSubview:onLineButton];
    
    STButton * offineButton = [[STButton alloc] initWithFrame:CGRectMake(onLineButton.right, line1.bottom, UIScreenWidth / 2, 54)
                                                        title:@"线下充值"
                                                   titleColor:KL_secendTextColor
                                                    titleFont:14
                                                 cornerRadius:0
                                              backgroundColor:nil
                                              backgroundImage:nil
                                                        image:nil];
    offineButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [offineButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedOfflineButton];
    }];
    [header addSubview:offineButton];
    
    STButton * rechargeButton = [[STButton alloc] initWithFrame:CGRectMake(0, onLineButton.bottom, UIScreenWidth , 55)
                                                          title:@"充值记录"
                                                     titleColor:KL_secendTextColor
                                                      titleFont:14
                                                   cornerRadius:0
                                                backgroundColor:nil
                                                backgroundImage:nil
                                                          image:[UIImage imageNamed:@"充值记录"]];
    rechargeButton.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    rechargeButton.titleEdgeInsets = UIEdgeInsetsMake(0, 25, 0, 0);
    [rechargeButton st_showTopLine];
    [rechargeButton st_showBottomLine];
    [rechargeButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedRechargeRecordButton];
    }];
    [header addSubview:rechargeButton];
    
    STButton * buyRecordButton = [[STButton alloc] initWithFrame:CGRectMake(0, rechargeButton.bottom, UIScreenWidth , 55)
                                                           title:@"消费记录"
                                                      titleColor:KL_secendTextColor
                                                       titleFont:14
                                                    cornerRadius:0
                                                 backgroundColor:nil
                                                 backgroundImage:nil
                                                           image:[UIImage imageNamed:@"交易记录"]];
    buyRecordButton.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    buyRecordButton.titleEdgeInsets = UIEdgeInsetsMake(0, 30, 0, 0);
    [buyRecordButton st_showBottomLine];
    [buyRecordButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedBuyRecordButton];
    }];
    [header addSubview:buyRecordButton];
    
    header.height = buyRecordButton.bottom;
    self.tableView.tableHeaderView = header;
}
#pragma mark --Action Method
- (void)onSlectedOnlineButton{
    if (!self.userModel) {
        [SVProgressHUD showErrorWithStatus:@"暂无用户信息，请稍后"];
        [self sendMyInfoRequest];
        return;
    }
    BLRechargeOnlineViewController * vc =  [BLRechargeOnlineViewController new];
    vc.userModel = self.userModel;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onSlectedOfflineButton{
    
    [self.navigationController pushViewController:[BLRechargeOffLineViewController new] animated:YES];
}
- (void)onSlectedRechargeRecordButton{
    [self.navigationController pushViewController:[BLRechageRecordViewController new] animated:YES];
}
- (void)onSlectedBuyRecordButton{
    
    [self.navigationController pushViewController:[BLConsumeViewController new] animated:YES];
}
- (void)sendMyInfoRequest{
    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:debugToken forKey:@"token"];
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php/Api/Basics/MemberListAction"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 self.userModel = [BLUserModel mj_objectWithKeyValues:responseObject[@"data"]];
                                                 
                                                 self.moneyLable.text = [NSString stringWithFormat:@"盖币:%@",self.userModel.balance];
                                                 self.pointLable.text = [NSString stringWithFormat:@"积分:%@",self.userModel.score];
                                                 self.washLable.text = [NSString stringWithFormat:@"本月洗涤:%@元",self.userModel.month_b];
                                                 self.lastWashLable.text = [NSString stringWithFormat:@"上月洗涤:%@元",self.userModel.month_s];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}

@end

